package com.bd.lrb_z.controller;

import com.bd.lrb_z.entity.User;
import com.bd.lrb_z.mapper.UserMapper;
import com.bd.lrb_z.mapper.VerifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;


@RestController
public class UserController {

    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg/check1")
    public int selectByMail(String mail){
        System.out.println("mail ===================== " + mail);
        User u =  mapper.selectByMail(mail);
        if (u != null){
            return 1;
        }
        return 0;
    }

    @RequestMapping("/reg")
    public int regInsert(User user,String vc,HttpSession sessionAC){
        System.out.println("user = " + user + ", vc = " + vc);
        System.out.println(sessionAC.getAttribute("verifyCode"));
        if (!vc .equals(sessionAC.getAttribute("verifyCode"))){
            return 2;
        }
        //查询用户是否存在
//        User u = mapper.selectByMail(user.getMail());
//        if (u!=null){
//            return 0;//用户名已存在!
//        }
        //把用户信息保存到数据库中
//        mapper.insert(user);
        sessionAC.removeAttribute("verifyCode");
        return 1;
    }


}
